package cc.core.pullrefresh;

import android.content.Context;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.View;
import android.widget.ListView;

/**
 * ClassName:PRListView <br/>
 * Date: 2015年6月22日 下午4:06:52 <br/>
 * 下拉刷新ListView，ListView的实现
 *
 * @author YuanChao
 */
public class PRListView extends PullRefreshAbsListViewBase<ListView> {
    private static final String TAG = "PRListView";

    public PRListView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public PRListView(Context context) {
        super(context);
    }

    @Override
    public void initFooter(Context context, AttributeSet attr) {
        super.initFooter(context, attr);
        listview.addFooterView(footerView);
    }

    @Override
    protected ListView initRefreshView(Context context, AttributeSet attrs, int defStyleAttr) {
        if (attrs == null && defStyleAttr == 0)
            listview = new ListView(context);
        else if (attrs != null && defStyleAttr == 0) {
            listview = new ListView(context, attrs);
        } else {
            listview = new ListView(context, attrs, defStyleAttr);
        }
        //        listview.setOverScrollMode(View.OVER_SCROLL_NEVER);
        return listview;
    }

    public void setSelection(int position) {
        getListview().setSelection(position);
    }

    /**
     * add headerView for ListView
     *
     * @param view
     */
    public void addHeaderView(View view) {
        getListview().addHeaderView(view);
    }

    /**
     * 设置顶部和底部的item的padding.
     *
     * @param padding 单位 DP
     */
    public void setClipToPadding(int padding) {
        listview.setClipToPadding(false);
        padding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, padding, getResources().getDisplayMetrics());
        topPadding = padding;
        listview.setPadding(padding, padding, padding, padding);
    }
}
